package com.soviet.boot.common.base;

import lombok.Data;
import lombok.Getter;

import java.io.Serializable;

/**
 * 结果模型
 *
 * @param <T>
 */
@Data
public class ResultModel<T> implements Serializable {
    private Integer code;
    private T data;
    private String msg;


    public ResultModel(T data) {
        this.code = ResultCode.SUCCESS.code;
        this.msg = ResultCode.SUCCESS.desc;
        this.data = data;
    }

    public ResultModel(ResultCode resultCode, T data) {
        this.code = resultCode.code;
        this.msg = resultCode.desc;
        this.data = data;
    }

    public ResultModel(ResultCode resultCode, T data, String msg) {
        this.code = resultCode.code;
        this.msg = msg;
        this.data = data;
    }


    @Getter
    public enum ResultCode {
        SUCCESS(200, "success"),
        ERROR(500, "系统异常"),
        FAIL(400, "fail"),
        VISIT_NOT_AUTHORIZED(401, "未授权"),
        ARGUMENT_ERROR(402, "参数错误"),
        ARGUMENT_EXCEPTION(407, "参数存在异常"),
        ARGUMENT_TOKEN_EMPTY(409, "Token为空"),
        LOGIN_FAIL(411, "登录失败"),
        ARGUMENT_TOKEN_INVALID(410, "Token无效"),
        SERVER_ERROR(501, "服务端异常"),
        COM_ERROR(502, "组件异常"),
        ACCESS_DENIED(503, "无权访问");

        ResultCode(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        private final Integer code;
        private final String desc;

    }


}
